package com.zhengdongzulin.zuke.app.work.activity

import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.lxj.androidktx.core.getVM
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.app.main.mine.collection.WorkListFragment
import com.zhengdongzulin.zuke.app.work.vm.ZKServiceEntranceVM
import com.zhengdongzulin.zuke.base.BaseActivity
import com.zhengdongzulin.zuke.databinding.ZkActivityWorkListBinding
import com.zhengdongzulin.zuke.ext.put
import com.zhengdongzulin.zuke.ext.start

/**
 * @类名称: CLASS
 * @类描述:
 * @创建人：Jeff
 * @创建时间：2021/6/9 20:53
 * @备注：
 */
class ZKWorkListActivity :
    BaseActivity<ZKServiceEntranceVM, ZkActivityWorkListBinding>() {

    var incidentType: String? = ""
    private val mTitles = arrayOf(
        "全部", "处理中", "待验收", "已完成"
    )
    private val mFragments = ArrayList<Fragment>()


    override fun getLayoutResId(): Int = R.layout.zk_activity_work_list

    override fun initVM(): ZKServiceEntranceVM = getVM(ZKServiceEntranceVM::class.java)

    override fun initView() {
        setTitleContent("工单列表")
        //incidentType，服务申请列表传：服务申请，报事报修列表传：报事工单,维修工单（逗号隔开）
        incidentType = intent.getStringExtra("incidentType")

        mView.ok.setBackgroundDrawable(GradientDrawable().apply {
            setColor(Color.parseColor("#1273f7"))
            cornerRadius = 10.0f
        })

        when (incidentType) {
            "服务申请" -> {
                setTitleContent("服务申请")
                mView.ok.setOnClickListener {
                    Intent().put("type", "Baojie").start(this, ZKAddWorkActivity::class.java)
                }
            }
            else -> {
                setTitleContent("我的报修")
                mView.ok.setOnClickListener {
                    Intent().put("type", "Weixiu").start(this, ZKAddWorkActivity::class.java)
                }
            }
        }

        mFragments.add(
            WorkListFragment.newInstance(
                "all"
            )
        )
        mFragments.add(
            WorkListFragment.newInstance(
                "processing"
            )
        )
        mFragments.add(
            WorkListFragment.newInstance(
                "accept"
            )
        )
        mFragments.add(
            WorkListFragment.newInstance(
                "complete"
            )
        )

        var mAdapter = MyPagerAdapter(
            supportFragmentManager
        )
        mView.vp.adapter = mAdapter
        mView.tl3.setViewPager(mView.vp, mTitles)
        mView.vp.setCurrentItem(0)

    }

    override fun initData() {

    }


    override fun initListener() {

    }

    override fun startObserve() {

    }

    inner class MyPagerAdapter(fm: FragmentManager?) :
        FragmentPagerAdapter(fm!!) {
        override fun getCount(): Int {
            return mFragments.size
        }

        override fun getPageTitle(position: Int): CharSequence? {
            return mTitles.get(position)
        }

        override fun getItem(position: Int): Fragment {
            return mFragments.get(position)
        }
    }


}